// import {defineConfig} from 'vite'
// import vue from '@vitejs/plugin-vue'
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
// import {resolve} from 'path'
// import * as path from "path";
//
// export default defineConfig({
//     const env = loadEnv(mode, process.cwd());
//     resolve: {
//         extensions: ['.ts', '.js', '.vue', '.json'],
//         alias: {
//             "@": path.join(__dirname, "./src"), // path记得引入
//         }
//     },
//     plugins: [
//         vue(),
//         AutoImport({
//             resolvers: [ElementPlusResolver()],
//         }),
//         Components({
//             resolvers: [ElementPlusResolver()],
//         }),
//     ],
//     server: {
//         hmr: true,
//         proxy: {
//             '^/api': {
//                 target: 'http://127.0.0.1:8000',
//                 target: env.VITE_API_URL,
//                 changeOrigin: true,
//                 rewrite: (path) => path.replace(/^\/api/, '')
//             }
//         }
//     },
//     css: {
//         // css预处理器
//         preprocessorOptions: {
//             scss: {
//                 charset: false,
//             },
//         },
//     }
// })
//


import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    const env = loadEnv(mode, process.cwd());
    return (
        {
            base: env.VITE_BASE_PATH,
            plugins: [vue()],
            resolve: {
                alias: {
                    "@": resolve(__dirname, "src"),
                }
            },
            server: {
                hmr: true,
                port:4173,
                proxy: {
                    // 选项写法
                    '^/api': {
                        target: env.VITE_API_URL,
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/api/, '')
                    } , // 选项写法
                    '^/proxy': {
                        target: "https://www.ihchina.cn/",
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/proxy/, '')
                    }
                }
            },
            css: {
                // css预处理器
                preprocessorOptions: {
                    scss: {
                        charset: false,
                        //需要在assets下创建对应的文件global.scss
                        // additionalData: '@import "./src/assets/style/global.scss";',
                    },
                },
            }
        }
    )
})
